package Renderer;
import java.util.ArrayList;

/**
 * A Stack specifically designed for storing TextProperty objects.
 * @author Nathan Scully
 * @version FINAL
 */
public class Stack {

    private ArrayList<TextProperty> stack;

    /**
     * The Constructor for the Stack, which should always contain one TextProperty 
     * object specifying the default font to be used unless otherwise specified.
     * @param theDefault This is the default font that should be used.
     */
    public Stack(TextProperty theDefault)
    {
        stack = new ArrayList<TextProperty>();
        stack.add(theDefault);
    }
    
    /**
     * Adds a TextProperty objecty to the Stack.
     * @param prop The TextProperty objects to be pushed.
     */
    public void Push(TextProperty prop)
    {
        stack.add(prop);
    }
    
    /**
     * Removes the most recently added TextProperty object from the Stack and 
     * returns it. 
     * If there is nothing to remove (except the default, which should never be 
     * removed), this method uses the peek() method instead and doesn't remove
     * anything.
     * @return The removed TextProperty object.
     */
    public TextProperty pop()
    {
        if(isEmpty()) // So that the default is never removed.
        {
            return peek();
        }
        return stack.remove(stack.size() - 1);
    }
    
    /**
     * Returns the most recently added TextProperty object, but does not remove it.
     * @return The most recently added TextProperty object.
     */
    public TextProperty peek()
    {
        return stack.get(stack.size() - 1);
    }

    /**
     * This returns whether or not the Stack contains anything else besides the
     * default. If not, the Stack is considered empty (even though it holds the
     * default TextProperty, so is technically not empty).
     * @return If the Stack is empty (ie: only contains default TextProperty).
     */
    public boolean isEmpty()
    {
        return stack.size() == 1; //1, not 0, as there must always be the default.
    }
}
